/*
    Copyright 2010 Northbranchlogic, Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 */

package com.norbl.runjrun;

import com.norbl.util.ec2.*;
import java.util.*;
import com.xerox.amazonws.ec2.*;

/**
 *
 * @author Barnet Wagman
 */
public class InstanceSpec {

    InstanceType instanceType;
    String imageID;
    String kernelID;
    int nInstances;
    String zone;
    NodeParams nodeParams;

        /**
         *
         * @param instanceType
         * @param imageID
         * @param kernelID usually <tt>null</tt> (uses default kernel).
         * @param nInstances
         * @param zone usually <tt>null</tt> (aws chooses zone within
         *      the ami's region).
         * @param nodeParams
         */
    public InstanceSpec(InstanceType instanceType,
                        String imageID,
                        String kernelID,
                        int nInstances,
                        String zone,
                        NodeParams nodeParams) {
        this.instanceType = instanceType;
        this.imageID = imageID;
        this.kernelID = kernelID;
        this.nInstances = nInstances;
        this.zone = zone;
        this.nodeParams = nodeParams;
    }

    public InstanceSpec(InstanceType instanceType,
                                            String imageID,
                                            int nInstances,
                                            NodeParams nodeParams) {
        this(instanceType,
             imageID,
             null, // kernel type
             nInstances,
             null, // zone
             nodeParams);
    }

    public int getNInstancesDesired() { return(nInstances); }

        /**
         *
         * @param eops
         * @param nNeeded
         * @return instance description objects.
         * @throws EC2Exception
         */
    public List<ReservationDescription.Instance> requestInstances(Ec2Ops eops, int nNeeded)
        throws EC2Exception {

        return( eops.requestInstances(instanceType, imageID, kernelID,
                                      nInstances, zone,
                                      nodeParams.toMessageString()) );
    }
}
